#include "StdAfx.h"
#include "LoanContractModel.h"
#include "CompanyMgr.h"


CLoanContractModel::CLoanContractModel(void)
{
	m_id = 0;
	m_consumerInfoID = 0;
	m_userID = 0;
	m_applyForTm = 0;
	m_loanType = 0;
	m_expenseType = 0;
	m_pdfinfoUpload = 0;
	m_status = 0;
}

CLoanContractModel::~CLoanContractModel(void)
{
}

void CLoanContractModel::parseFromJson(Json::Value& jsonData)
{
	if (!jsonData["id"].isNull())
	{
		this->m_id = jsonData["id"].asInt();
	}
	if (!jsonData["contractNo"].isNull())
	{
		this->m_contractNo = jsonData["contractNo"].asCString();
	}
	if (!jsonData["consumerInfoID"].isNull()) 
	{
		this->m_consumerInfoID = jsonData["consumerInfoID"].asInt();
	}
	if (!jsonData["userID"].isNull()) 
	{
		this->m_userID = jsonData["userID"].asInt();
	}
	if (!jsonData["applyForTm"].isNull()) 
	{
		this->m_applyForTm = jsonData["applyForTm"].asInt64();
	}
	if (!jsonData["consumerIdentity"].isNull()) 
	{
		this->m_consumerIdentity = jsonData["consumerIdentity"].asCString();
	}
	if (!jsonData["phoneNum1"].isNull()) 
	{
		this->m_phoneNum1 = jsonData["phoneNum1"].asCString();
	}
	if (!jsonData["phoneNum2"].isNull()) 
	{
		this->m_phoneNum2 = jsonData["phoneNum2"].asCString();
	}
	if (!jsonData["loanType"].isNull()) 
	{
		this->m_loanType = jsonData["loanType"].asInt();
	}
	if (!jsonData["expenseType"].isNull()) 
	{
		this->m_expenseType = jsonData["expenseType"].asInt();
	}
	if (!jsonData["pdfinfoUpload"].isNull()) 
	{
		this->m_pdfinfoUpload = jsonData["pdfinfoUpload"].asInt();
	}
	if (!jsonData["status"].isNull()) 
	{
		this->m_status = jsonData["status"].asInt();
	}
	if (!jsonData["contractFile"].isNull()) 
	{
		this->m_contractFile = jsonData["contractFile"].asCString();
	}

	CUtils::getJsonStringField(jsonData, "consumerName", m_consumerName);
	CUtils::getJsonStringField(jsonData, "applyAmount", m_applyAmount);
	CUtils::getJsonStringField(jsonData, "expenseValue", m_expenseValue);
	CUtils::getJsonStringField(jsonData, "earnestMoney", m_earnestMoney);
	CUtils::getJsonStringField(jsonData, "consumerAddr", m_consumerAddr);
	CUtils::getJsonStringField(jsonData, "supplementMemo", m_supplementMemo);
	CUtils::getJsonStringField(jsonData, "contractSignAddr", m_contractSignAddr);
}

CString CLoanContractModel::getContractPdfFileName() 
{
	CString strContractPdfName;
	UserInfo* pUser = CCompanyMgr::getInstance()->getUserInfoByUserID(m_userID);
	if (pUser != nullptr)
	{
		int fileNameLen = m_contractFile.GetLength();
		if (fileNameLen > 5)
		{
			strContractPdfName.Format(_T("%s_%s_%s"), m_consumerName, pUser->m_userName, m_contractFile.Mid(fileNameLen-9));
		}
		else
		{
			strContractPdfName.Format(_T("%s_%s_%s.pdf"), m_consumerName, pUser->m_userName, m_contractNo);
		}					
	}
	else
	{
		if (m_contractFile.GetLength() > 5)
		{
			strContractPdfName.Format(_T("%s_%s"), m_consumerName, m_contractFile);
		}
		else
		{
			strContractPdfName.Format(_T("%s_%s.pdf"), m_consumerName, m_contractNo);
		}		
	}

	return strContractPdfName;
}

CString CLoanContractModel::getMainProductPdfFileServerName()
{
	CString strContractPdfName;
	ConsumerProductModel* pMainProduct = CCompanyMgr::getInstance()->getMainProductByContractID(m_id);
	if (pMainProduct != nullptr)
	{			
		strContractPdfName.Format(_T("%s_%d_%d.pdf"), pMainProduct->m_productNo, m_id, m_userID);			
	}

	return strContractPdfName;
}

CString CLoanContractModel::getContractPdfFileServerName()
{
	CString strContractPdfName;		
	strContractPdfName.Format(_T("%s_%d_%d.pdf"), m_contractNo, m_id, m_userID);

	return strContractPdfName;
}

